package demo005;
/**
 * String 的用法
 * @author zanglaowei
 *
 */
public class demoString {
	public static void main(String args[]){
		
		demoString me=new demoString();
		me.testA();
		me.testB();
		System.out.println("-------------StringBuilder------------------");
		me.testStringBuilder();
		System.out.println("-------------getChars------------------");
		me.testGetChars();
	}
	/**
	 * 测试String相等
	 */
	public  void testA(){
		String strA="1234";
		String strB=new String("1234");
		System.out.println(strA==strB);//false
		System.out.println(strA.equals(strB));//true
	}
	
	public void testB(){
		String strTest=new String("Hello,String");
		System.out.println("method 1 of subsString:"+strTest.substring(4));
		System.out.println("method 2 of subString:"+strTest.substring(1, 4));
		
		System.out.println(strTest.indexOf("l"));
		System.out.println(strTest.lastIndexOf("l"));
	}
	
//	replace用法
	public void testC(){
		
	}
//	split 用法
	
	//StringBuilder
	public void testStringBuilder(){
		StringBuilder bud = new StringBuilder();
		
		bud.append("\nHello").append("\nWorld");
		System.out.println(bud.toString());
	}
	//StringBuffer
	public void testStringBuffer(){
	
	}
	
	//getChars
	public void testGetChars(){
		String Str1 = new String("www.runoob.com");
        char[] Str2 = new char[7];

		try {
		    Str1.getChars(4, 10, Str2, 1);
		    System.out.println("拷贝的字符串为：" );
		    System.out.println(Str2[0]);
		    System.out.println(Str2);
		} catch( Exception ex) {
		    System.out.println("testGetChars-触发异常..."+ex.getMessage());
		}
	}
	
	
}
